package com.bidevalution.controller.util;

import java.util.Map;

import org.apache.log4j.Logger;

import com.qtp.core.util.GsonUtil;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.cvm.v20170312.models.DescribeZonesRequest;
import com.tencentcloudapi.live.v20180801.LiveClient;
import com.tencentcloudapi.live.v20180801.models.DescribeLiveStreamStateRequest;
import com.tencentcloudapi.live.v20180801.models.DescribeLiveStreamStateResponse;
import com.tencentcloudapi.live.v20180801.models.DropLiveStreamRequest;
import com.tencentcloudapi.live.v20180801.models.DropLiveStreamResponse;
import com.tencentcloudapi.live.v20180801.models.ResumeLiveStreamRequest;
import com.tencentcloudapi.live.v20180801.models.ResumeLiveStreamResponse;

public class LiveSdkUtil {
	private static final Logger logger = Logger.getLogger(LiveSdkUtil.class);
	public static void main(String[] args) throws Exception {

	}

	public static void dropStream(String secretId,String secretKey,String domainName, String appName, String streamName) {
		try {
			// 实例化一个认证对象，入参需要传入腾讯云账户 secretId，secretKey
			Credential cred = new Credential(secretId, secretKey);

			// 实例化要请求产品(以 CVM 为例)的 client 对象
			// 实例化一个http选项，可选的，没有特殊需求可以跳过
			HttpProfile httpProfile = new HttpProfile();
			httpProfile.setReqMethod("POST"); // post请求(默认为post请求)
			httpProfile.setConnTimeout(60); // 请求连接超时时间，单位为秒(默认60秒)
			httpProfile.setEndpoint("live.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)

			ClientProfile clientProfile = new ClientProfile();
			clientProfile.setUnsignedPayload(true);
			clientProfile.setHttpProfile(httpProfile);
			// 实例化要请求产品的client对象,clientProfile是可选的
			LiveClient client = new LiveClient(cred, "", clientProfile);
			// 实例化一个请求对象
			DropLiveStreamRequest req = new DropLiveStreamRequest();
			req.setDomainName(domainName);
			req.setAppName(appName);
			req.setStreamName(streamName);
			// 通过 client 对象调用想要访问的接口，需要传入请求对象
			DropLiveStreamResponse resp = client.DropLiveStream(req);
			// 输出 JSON 格式的字符串回包
			logger.info("断开直播流结果:" + DescribeZonesRequest.toJsonString(resp));
		} catch (TencentCloudSDKException e) {
			logger.error(e.getMessage(), e);
		}

	}

	public static void resumeStream(String secretId,String secretKey,String domainName, String appName, String streamName) {
		try {
			// 实例化一个认证对象，入参需要传入腾讯云账户 secretId，secretKey
			Credential cred = new Credential(secretId, secretKey);

			// 实例化要请求产品(以 CVM 为例)的 client 对象
			// 实例化一个http选项，可选的，没有特殊需求可以跳过
			HttpProfile httpProfile = new HttpProfile();
			httpProfile.setReqMethod("POST"); // post请求(默认为post请求)
			httpProfile.setConnTimeout(60); // 请求连接超时时间，单位为秒(默认60秒)
			httpProfile.setEndpoint("live.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)

			ClientProfile clientProfile = new ClientProfile();
			clientProfile.setUnsignedPayload(true);
			clientProfile.setHttpProfile(httpProfile);
			// 实例化要请求产品的client对象,clientProfile是可选的
			LiveClient client = new LiveClient(cred, "", clientProfile);
			// 实例化一个请求对象
			ResumeLiveStreamRequest req = new ResumeLiveStreamRequest();
			req.setDomainName(domainName);
			req.setAppName(appName);
			req.setStreamName(streamName);
			// 通过 client 对象调用想要访问的接口，需要传入请求对象
			ResumeLiveStreamResponse resp = client.ResumeLiveStream(req);
			// 输出 JSON 格式的字符串回包
			logger.info("恢复直播流结果:" + DescribeZonesRequest.toJsonString(resp));
		} catch (TencentCloudSDKException e) {
			logger.error(e.getMessage(), e);
		}

	}

	public static Map<String, Object> getStreamState(String secretId,String secretKey,String domainName, String appName, String streamName) {
		try {
			// 实例化一个认证对象，入参需要传入腾讯云账户 secretId，secretKey
			Credential cred = new Credential(secretId, secretKey);

			// 实例化要请求产品(以 CVM 为例)的 client 对象
			// 实例化一个http选项，可选的，没有特殊需求可以跳过
			HttpProfile httpProfile = new HttpProfile();
			httpProfile.setReqMethod("POST"); // post请求(默认为post请求)
			httpProfile.setConnTimeout(60); // 请求连接超时时间，单位为秒(默认60秒)
			httpProfile.setEndpoint("live.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)

			ClientProfile clientProfile = new ClientProfile();
			clientProfile.setUnsignedPayload(true);
			clientProfile.setHttpProfile(httpProfile);
			// 实例化要请求产品的client对象,clientProfile是可选的
			LiveClient client = new LiveClient(cred, "", clientProfile);
			// 实例化一个请求对象
			DescribeLiveStreamStateRequest req = new DescribeLiveStreamStateRequest();
			req.setDomainName(domainName);
			req.setAppName(appName);
			req.setStreamName(streamName);
			// 通过 client 对象调用想要访问的接口，需要传入请求对象
			DescribeLiveStreamStateResponse resp = client.DescribeLiveStreamState(req);
			// 输出 JSON 格式的字符串回包
			return GsonUtil.jsonToMapWithGson(DescribeZonesRequest.toJsonString(resp));
		} catch (TencentCloudSDKException e) {
			logger.error(e.getMessage(), e);
		}
		return null;
	}
}
